﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ReadyApps.Wiki;

namespace ReadyAppsTest.Wiki
{
    [TestClass]
    public class WikiPageRequestTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Constructor Tests

        [TestMethod]
        public void WikiPageRequestConstructorTest()
        {
            List<Tuple<string, string, string>> data = new List<Tuple<string, string, string>>();
            data.Add(new Tuple<string, string, string>(null, "/", "Default"));
            data.Add(new Tuple<string, string, string>(string.Empty, "/", "Default"));
            data.Add(new Tuple<string, string, string>("page", "/", "page"));
            data.Add(new Tuple<string, string, string>("folder/", "/folder/", "Default"));
            data.Add(new Tuple<string, string, string>("folder/page", "/folder/", "page"));
            data.Add(new Tuple<string, string, string>("folder1/folder2/", "/folder1/folder2/", "Default"));
            data.Add(new Tuple<string, string, string>("folder1/folder2/page", "/folder1/folder2/", "page"));

            string siteName = "site";
            string baseFolder = "baseFolder";
            string username = "user";
            foreach (var row in data)
            {
                WikiPageRequest target = new WikiPageRequest(siteName, baseFolder, username, row.Item1, true);
                Assert.AreEqual(row.Item2, target.RequestedFolder, "Failed on input " + row.Item1 + " and folder name");
                Assert.AreEqual(row.Item3, target.RequestedPage, "Failed on input " + row.Item1 + " and page name");
            }
        }

        #endregion

        #region GetFullPath Tests

        [TestMethod]
        public void WikiPageRequestGetFullPathTest()
        {
            List<Tuple<string, string, string>> data = new List<Tuple<string, string, string>>();
            data.Add(new Tuple<string, string, string>("/base", null, "/base/"));
            data.Add(new Tuple<string, string, string>("/base/", null, "/base/"));
            data.Add(new Tuple<string, string, string>("/base", string.Empty, "/base/"));
            data.Add(new Tuple<string, string, string>("/base/", string.Empty, "/base/"));
            data.Add(new Tuple<string, string, string>("/base", "page", "/base/"));
            data.Add(new Tuple<string, string, string>("/base/", "page", "/base/"));
            data.Add(new Tuple<string, string, string>("/base", "folder/", "/base/folder/"));
            data.Add(new Tuple<string, string, string>("/base/", "folder/", "/base/folder/"));
            data.Add(new Tuple<string, string, string>("/base", "folder/page", "/base/folder/"));
            data.Add(new Tuple<string, string, string>("/base/", "folder/page", "/base/folder/"));
            data.Add(new Tuple<string, string, string>("/base", "folder1/folder2/", "/base/folder1/folder2/"));
            data.Add(new Tuple<string, string, string>("/base/", "folder1/folder2/", "/base/folder1/folder2/"));
            data.Add(new Tuple<string, string, string>("/base", "folder1/folder2/page", "/base/folder1/folder2/"));
            data.Add(new Tuple<string, string, string>("/base/", "folder1/folder2/page", "/base/folder1/folder2/"));

            string siteName = "site";
            string username = "user";
            foreach (var row in data)
            {
                WikiPageRequest target = new WikiPageRequest(siteName, row.Item1, username, row.Item2, true);
                Assert.AreEqual(row.Item3, target.GetFullPath(), "Failed on input " + row.Item1 + " and " + row.Item2);
            }
        }

        #endregion
    }
}
